export function timeDifference(timestamp) {
  const now = new Date().getTime();
  const diff = now - timestamp;

  if (diff < 60 * 1000) {
    return "1分钟";
  } else if (diff < 60 * 60 * 1000) {
    return Math.floor(diff / (60 * 1000)) + "分钟";
  } else if (diff < 24 * 60 * 60 * 1000) {
    return Math.floor(diff / (60 * 60 * 1000)) + "小时";
  } else if (diff < 30 * 24 * 60 * 60 * 1000) {
    return Math.floor(diff / (24 * 60 * 60 * 1000)) + "天";
  } else {
    return null;
  }
}

export function gotoHome() {
  uni.showModal({
    title: "提示",
    content: "页面有误将返回首页",
    showCancel: false,
    success: (res) => {
      if (res.confirm) {
        uni.reLaunch({
          url: "/pages/index/index",
        });
      }
    },
  });
}
